const { port } = require('./config/index');
const { createServer } = require('http');
const Koa = require('koa');
const koaBody = require('koa-body');
const app = new Koa();
const router = require('./router/index');
const httpServer = createServer(app.callback());
require('./socket/index')(httpServer);

app.use(async (ctx, next) => {
  ctx.set('Content-Type', 'application/json;charset=utf-8');
  await next();
});

app.use(koaBody());
app.use(router.routes());

httpServer.listen(port, () => {
  console.log(`http://localhost:${port}`);
});
